package ar.com.ford.it.fullEconomics.persistence.dao.query;

import java.sql.Timestamp;
import oracle.toplink.expressions.Expression;
import oracle.toplink.expressions.ExpressionBuilder;
import ar.com.ford.it.fullEconomics.persistence.dto.Teesp05Pricing;
import com.ford.it.persistence.impl.toplink.CustomExpressionFactory;

public class FindOverloadPricingQuery implements CustomExpressionFactory {
    /**
     * Busca si existe un pricing con ese supply en esas fechas
     */
    public Expression createExpression(ExpressionBuilder builder,
                                       Object[] parameters) {
        Expression exp = null;

        Teesp05Pricing supply = (Teesp05Pricing) parameters[0];
        Timestamp EffDateInStart = (Timestamp) parameters[1];
        Timestamp EffDateInEnd = (Timestamp) parameters[2];
        Integer sortDateInDateOut = (Integer) parameters[3];//0 para date in, 1 para date out

        exp = builder.get("teesp04Supply").equal(supply.getTeesp04Supply());
        if (sortDateInDateOut.intValue() == 0){
        exp = exp.and(builder.get("eesp05PriceEffectiveDateY").between(EffDateInStart,EffDateInEnd));
        }else if(sortDateInDateOut.intValue() ==1)
            exp = exp.and(builder.get("eesp05PriceEndDateY").between(EffDateInStart,EffDateInEnd));
    return exp;
    }
}
